package Mapper;
import pojo.VirtualProduct;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface VirtualProductMapper {
    @Select("SELECT * FROM virtual_product")
    List<VirtualProduct> findAll();

    @Select("SELECT * FROM virtual_product WHERE category_id = #{cid}")
    List<VirtualProduct> findByCategory(Long cid);

    @Select("SELECT * FROM virtual_product WHERE id = #{id}")
    VirtualProduct findById(Long id);

    @Update("UPDATE virtual_product SET stock = stock - #{quantity} WHERE id = #{id}")
    int reduceStock(@Param("id") Long id, @Param("quantity") Integer quantity);
}